#include <cstdio>

using namespace std;

const int maxn=100000, maxm=100000;

int n, m, ind[maxn+1], to[2*maxn-1], link[2*maxn-1],
    indx[maxn+1], indy[maxn+1], linkx[maxm+1], linky[maxm+1], sco[maxm+1][3];

int max(int a, int b) {return a>b ? a : b;}

void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
}

int solve(int o, int fa, int sum) {
    static bool book[maxm+1];
    for (int i=indx[o]; i; i=linkx[i]) book[i] = true;
    for (int i=indy[o]; i; i=linky[i]) {
        if (book[i]) sum += sco[i][0];
    }

    int ret=sum;
    for (int i=ind[o]; i; i=link[i]) {
        if (to[i]!=fa) {
            ret = max(ret, solve(to[i], o, sum));
        }
    }

    for (int i=indx[o]; i; i=linkx[i]) book[i] = false;
    return ret;
}

int main() {
    freopen("score.in", "r", stdin);
    freopen("check.out", "w", stdout);

    int m;
    scanf("%d %d", &n, &m);
    for (int i=1; i<n; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        addSide(x, y);
        addSide(y, x);
    }

    for (int i=1; i<=m; i++) {
        scanf("%d %d %d", sco[i]+1, sco[i]+2, sco[i]);
        linkx[i] = indx[sco[i][1]], linky[i] = indy[sco[i][2]];
        indx[sco[i][1]] = indy[sco[i][2]] = i;
    }

    int ans=0;
    for (int i=1; i<=n; i++) {
        ans = max(ans, solve(i, 0, 0));
    }
    printf("%d\n", ans);

    fclose(stdin);
    fclose(stdout);
    return 0;
}
